<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<p>数据1：<input type="text" id="num1"></p>
<p>数据2: <input type="text" id="num2"></p>
<p>
    <button onclick="change('jia')">相加</button>
    <button onclick="change('jian')">相减</button>
    <button onclick="change('cheng')">相乘</button>
    <button onclick="change('chu')">相除</button>
</p>
<p>结果：<input type="text" id="result"></p>

<script>
    function change(e){
        var num1 =document.querySelector("#num1").value;
        var num2 =document.querySelector("#num2").value;
        num1 = Number(num1);
        num2 = Number(num2);
        switch (e){
            case 'jia':
                res = num1 + num2;
                break;
            case 'jian':
                res = num1 - num2;
                break;
            case 'cheng':
                res = num1 * num2;
                break;
            case 'chu':
                res = num1 / num2;
                break;
        }
        document.querySelector("#result").value = res;
    }
</script>
</body>
</html>